<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>借阅管理</title>
    <link href="../../component/pear/css/pear.css" rel="stylesheet"/>
</head>
<body class="pear-container">
<!--检索组件-->
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">书名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="title" placeholder="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">出版社</label>
                    <div class="layui-input-inline">
                        <input type="text" name="publish" placeholder="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">作者</label>
                    <div class="layui-input-inline">
                        <input type="text" name="author" placeholder="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="borrows-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<!--信息显示组件-->
<div class="layui-card">
    <div class="layui-card-body">
        <table id="borrows-table" lay-filter="borrows-table"></table>
    </div>
</div>
<!--催还组件-->
<div style="display: none" id="showBorrow">
    <form class="layui-form" action="">
        <div class="mainBox">
            <div class="main-container">
                <table border="1" cellpadding="0" id="borrowsInfo" lay-filter="borrowsInfo">
                    <thead align="center">
                    <td>书名</td>
                    <td>借书时间</td>
                    <td>最后还书时间</td>
                    <td>作者</td>
                    <td>类别</td>
                    </thead>
                    <tbody align="center">
                    <td width="80" id="title"></td>
                    <td width="180" id="botime"></td>
                    <td width="180" id="lasttime"></td>
                    <td width="80" id="author"></td>
                    <td width="80" id="btype"></td>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="bottom" id="borrowsInfo-event">
            <div class="button-container">
                <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" lay-submit="">
                    催还
                </button>
                <button id="close" type="button" class="layui-btn layui-btn-sm" lay-submit="" lay-event="close">
                    <i class="layui-icon layui-icon-close"></i>
                    关闭
                </button>
            </div>
        </div>
    </form>
</div>
<!--操作按钮组件-->
<script type="text/html" id="borrows-bar">
    <button class="pear-btn pear-btn-warming pear-btn-sm" lay-event="power"><i
            class="layui-icon layui-icon-vercode"></i></button>
</script>
<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<script>
    layui.use(['table', 'form', 'jquery'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let MODULE_PATH = "operate/";
        //设置表头信息
        let cols = [
            [
                {
                    title: '书名',
                    field: 'title',
                    align: 'center',
                },
                {
                    title: 'ISBN',
                    field: 'isbn',
                    align: 'center'
                },
                {
                    title: '出版社',
                    field: 'publish',
                    align: 'center'
                },
                {
                    title: '类别',
                    field: 'btype',
                    align: 'center'
                },
                {
                    title: '作者',
                    field: 'author',
                    align: 'center'
                },
                {
                    title: '总数',
                    field: 'totalnum',
                    align: 'center',
                    sort: true
                },
                {
                    title: '剩余数量',
                    field: 'surplusnum',
                    align: 'center'
                },
                {
                    title: '借书人',
                    field: 'uid',
                    align: 'center'
                },
                {
                    title: '借书时间',
                    field: 'botime',
                    align: 'center',
                },
                {
                    title: '操作',
                    toolbar: '#borrows-bar',
                    align: 'center'
                }
            ]
        ]
        //表格数据填充
        table.render({
            elem: '#borrows-table',
            url: 'http://localhost:8080/borrows/select',
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: '#borrows-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports']
        });

        table.on('tool(borrows-table)', function (obj) {
             if (obj.event === 'power') {
                window.power(obj);
            }
        });

        form.on('submit(borrows-query)', function (data) {
            table.reload('borrows-table', {
                where: data.field,
                pager: {curr:1}
            })
            return false;
        });
        window.power = function (obj) {
            var index = layer.open({
                type: 1,
                title: '详情',
                shade: 0.1,
                area: ['600px', '320px'],
                content: $('#showBorrow'),
                success:function (layero,index){
                    let title_inp = $(layero).find("#showBorrow").contents().find("#title");
                    title_inp.text(obj.data.title);

                    let botime_inp = $(layero).find("#showBorrow").contents().find("#botime");
                    botime_inp.text(layui.util.toDateString(obj.data.botime, 'yyyy-MM-dd HH:mm:ss')) ;

                    let lasttime_inp = $(layero).find("#showBorrow").contents().find("#lasttime");
                    lasttime_inp.text(layui.util.toDateString(obj.data.lasttime, 'yyyy-MM-dd HH:mm:ss'));

                    let author_inp = $(layero).find("#showBorrow").contents().find("#author");
                    author_inp.text(obj.data.author);

                    let type_inp = $(layero).find("#showBorrow").contents().find("#btype");
                    type_inp.text(obj.data.btype);

                }
            });
            //监听关闭按钮
            $('#showBorrow').on('click','#close',function (){
                layer.close(index);
            })
        }
        window.refresh = function () {
            table.reload('borrows-table');
        }
    })
</script>
</body>
</html>
